Return * for n number of times


Posted by Christy on 2022-04-19

Description: Write a function that accepts a number n and returns * for n number of times

function star(n) {

}

console.log(star(3)); // ***
function star(n) {
  let result = "";
  for (let i = 1; i <= n; i++) {
    result += "*";
  }
  return result;
}

console.log(star(3));

Be careful about the way of ouput, if it's print -> console.log; if it's return -> return










Related Posts

在 AWS 上使用 Docker 安裝 Jitsi

在 AWS 上使用 Docker 安裝 Jitsi

〈 C++學習日記 #1〉指標 Pointer (Part.1)

〈 C++學習日記 #1〉指標 Pointer (Part.1)

ES6 解構賦值

ES6 解構賦值


Comments